import java.util.StringTokenizer;
import java.util.Vector;

class P624 {

	public static void main(String[] args) {
		String line = readLn();
		while (line != null) {
			process(line);
			line = readLn();
		}
	}

	private static void process(String line) {
		StringTokenizer st = new StringTokenizer(line);
		int N = Integer.parseInt(st.nextToken());
		int length = Integer.parseInt(st.nextToken());
		int[] array = new int[length];
		for (int k = 0; k < length; k++) {
			array[k] = Integer.parseInt(st.nextToken());
		}
		
		ks(array, N);
		
	}

	private static void ks(int[] array, int mw) {
		int[][] table = new int[array.length+1][mw+1];
		for (int i=0;i<=array.length ;i++) table[i][0] = 0;
		for (int w=0;w<=mw;w++) table[0][w] = 0;

		for (int i=1;i<=array.length;i++) {
		  for (int w=1;w<=mw;w++) {
		    if (array[i-1] > w)
		      table[i][w] = table[i-1][w];
		    else
		      table[i][w] = max(table[i-1][w] , table[i-1][w-array[i-1]]+array[i-1]);
		  }
		}
		
		int y = array.length;
		int x = mw;
		
		Vector solutions = new Vector();
		
		while ( (x > 0 && y > 0) ) {
			if (table[y][x] != table[y-1][x]) {
				solutions.addElement(new Integer(array[y-1]));
				x -= array[y-1];
				y--;
			} else {
				y--;
			}
		}
		
//		System.out.println(y);
//		if (i >= 1) {
//			solutions.addElement(new Integer(array[i-1]));
//		}

		int length = array.length;
		
		for (int k = 0; k < length; k++) {
			if (solutions.contains(new Integer(array[k]))) {
				System.out.print(array[k] + " ");
			}
		}
		
//		System.out.println(solutions);
		System.out.println("sum:" + table[array.length][mw]);
	}

	private static int max(int i, int j) {
		return i >= j ? i : j;
	}

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

}
